﻿using System;
using System.Collections;
using System.Xml;
using WeiSha.Core.Param.Method;

namespace WeiSha.Core
{
	// Token: 0x02000010 RID: 16
	public class CustomConfigItem : IEnumerable
	{
		// Token: 0x1700001B RID: 27
		// (get) Token: 0x06000065 RID: 101 RVA: 0x00004194 File Offset: 0x00002394
		// (set) Token: 0x06000066 RID: 102 RVA: 0x000041AC File Offset: 0x000023AC
		public string Key
		{
			get
			{
				return this._key;
			}
			set
			{
				this._key = value;
				bool flag = this._node.Attributes["key"] == null;
				if (flag)
				{
					((XmlElement)this._node).SetAttribute("key", this._key);
				}
				else
				{
					this._node.Attributes["key"].Value = value;
				}
				this.Refresh();
			}
		}

		// Token: 0x1700001C RID: 28
		// (get) Token: 0x06000067 RID: 103 RVA: 0x00004224 File Offset: 0x00002424
		// (set) Token: 0x06000068 RID: 104 RVA: 0x0000423C File Offset: 0x0000243C
		public string Text
		{
			get
			{
				return this._text;
			}
			set
			{
				this._text = value;
				bool flag = this._node.Attributes["value"] == null;
				if (flag)
				{
					((XmlElement)this._node).SetAttribute("value", this._text);
				}
				else
				{
					this._node.Attributes["value"].Value = value;
				}
				this.Refresh();
			}
		}

		// Token: 0x1700001D RID: 29
		// (get) Token: 0x06000069 RID: 105 RVA: 0x000042B4 File Offset: 0x000024B4
		public ConvertToAnyValue Value
		{
			get
			{
				return new ConvertToAnyValue(this._text);
			}
		}

		// Token: 0x1700001E RID: 30
		// (get) Token: 0x0600006A RID: 106 RVA: 0x000042D4 File Offset: 0x000024D4
		public CustomConfigItem[] Childs
		{
			get
			{
				return this._childs;
			}
		}

		// Token: 0x1700001F RID: 31
		// (get) Token: 0x0600006B RID: 107 RVA: 0x000042EC File Offset: 0x000024EC
		public XmlNode Node
		{
			get
			{
				return this._node;
			}
		}

		// Token: 0x0600006C RID: 108 RVA: 0x00004304 File Offset: 0x00002504
		public CustomConfigItem(XmlNode node)
		{
			this._node = node;
			this.Refresh();
		}

		// Token: 0x0600006D RID: 109 RVA: 0x00004324 File Offset: 0x00002524
		public void Refresh()
		{
			this._key = ((this._node.Attributes["key"] != null) ? this._node.Attributes["key"].Value : "");
			this._text = ((this._node.Attributes["value"] != null) ? this._node.Attributes["value"].Value : "");
			XmlNodeList childNodes = this._node.ChildNodes;
			bool flag = childNodes.Count > 0;
			if (flag)
			{
				this._childs = new CustomConfigItem[childNodes.Count];
				for (int i = 0; i < this._childs.Length; i++)
				{
					this._childs[i] = new CustomConfigItem(childNodes[i]);
				}
			}
		}

		// Token: 0x0600006E RID: 110 RVA: 0x00004408 File Offset: 0x00002608
		public CustomConfigItem ChildAdd(string key, string value)
		{
			CustomConfigItem customConfigItem = null;
			bool flag = this.Childs != null;
			if (flag)
			{
				foreach (CustomConfigItem customConfigItem2 in this.Childs)
				{
					bool flag2 = customConfigItem2.Key.ToLower() == key.ToLower().Trim();
					if (flag2)
					{
						customConfigItem = customConfigItem2;
						break;
					}
				}
			}
			bool flag3 = customConfigItem == null;
			if (flag3)
			{
				XmlDocument ownerDocument = this._node.OwnerDocument;
				XmlNode xmlNode = ownerDocument.CreateNode("element", "item", "");
				XmlElement xmlElement = (XmlElement)xmlNode;
				xmlElement.SetAttribute("key", key);
				xmlElement.SetAttribute("value", value);
				this._node.AppendChild(xmlNode);
			}
			else
			{
				this.ChildUpdate(key, value);
			}
			this.Refresh();
			return this.ChildSingle(key);
		}

		// Token: 0x0600006F RID: 111 RVA: 0x000044F4 File Offset: 0x000026F4
		public void ChildDelete(string key)
		{
			XmlNodeList childNodes = this._node.ChildNodes;
			foreach (object obj in childNodes)
			{
				XmlNode xmlNode = (XmlNode)obj;
				bool flag = xmlNode.Attributes["key"].Value.ToLower() == key.ToLower().Trim();
				if (flag)
				{
					this._node.RemoveChild(xmlNode);
				}
			}
			this.Refresh();
		}

		// Token: 0x06000070 RID: 112 RVA: 0x0000459C File Offset: 0x0000279C
		public CustomConfigItem ChildUpdate(string key, string value)
		{
			XmlNodeList childNodes = this._node.ChildNodes;
			foreach (object obj in childNodes)
			{
				XmlNode xmlNode = (XmlNode)obj;
				bool flag = xmlNode.Attributes["key"].Value.ToLower() == key.ToLower().Trim();
				if (flag)
				{
					((XmlElement)xmlNode).SetAttribute("value", value);
				}
			}
			this.Refresh();
			return this.ChildSingle(key);
		}

		// Token: 0x06000071 RID: 113 RVA: 0x00004654 File Offset: 0x00002854
		public CustomConfigItem ChildUpdate(int index, string key, string value)
		{
			XmlNodeList childNodes = this._node.ChildNodes;
			bool flag = index >= 0 && index < childNodes.Count;
			if (flag)
			{
				XmlElement xmlElement = (XmlElement)childNodes[index];
				xmlElement.SetAttribute("key", key);
				xmlElement.SetAttribute("value", value);
			}
			this.Refresh();
			return this.ChildSingle(key);
		}

		// Token: 0x06000072 RID: 114 RVA: 0x000046C0 File Offset: 0x000028C0
		public CustomConfigItem ChildSingle(string key)
		{
			bool flag = this.Childs == null;
			if (flag)
			{
				this.ChildAdd(key, "");
			}
			CustomConfigItem customConfigItem = null;
			foreach (CustomConfigItem customConfigItem2 in this.Childs)
			{
				bool flag2 = customConfigItem2.Key.ToLower() == key.ToLower().Trim();
				if (flag2)
				{
					customConfigItem = customConfigItem2;
					break;
				}
			}
			bool flag3 = customConfigItem == null;
			CustomConfigItem customConfigItem3;
			if (flag3)
			{
				customConfigItem3 = this.ChildAdd(key, "");
			}
			else
			{
				customConfigItem3 = customConfigItem;
			}
			return customConfigItem3;
		}

		// Token: 0x06000073 RID: 115 RVA: 0x00004750 File Offset: 0x00002950
		public IEnumerator GetEnumerator()
		{
			bool flag = this._childs != null;
			if (flag)
			{
				int num;
				for (int i = 0; i < this._childs.Length; i = num + 1)
				{
					yield return this._childs[i];
					num = i;
				}
			}
			yield break;
		}

		// Token: 0x04000020 RID: 32
		private string _key;

		// Token: 0x04000021 RID: 33
		private string _text;

		// Token: 0x04000022 RID: 34
		private CustomConfigItem[] _childs;

		// Token: 0x04000023 RID: 35
		private XmlNode _node = null;
	}
}
